 var isPlaying=false;
	var isPause=false;
	var isReleased=false;
	var timer;
//开始和暂停播放
    function playMusic(){
		var src=$("#playBut").attr("src");
		if(src=="images/play.png")
		{
			$("#playBut").attr("src","images/stop.png");
			 var musicList=JSON.parse(storage.getItem("musicList"));
			PlayerPlugin.player("playMusic",musicList[playPosition]);
			timer=setInterval("progress()",1000);
		}else
		{
			$("#playBut").attr("src","images/play.png");
			PlayerPlugin.player("pauseMusic","");
		}
			
    }
   
    //上一首
    function pre(){
           var musicList=JSON.parse(storage.getItem("musicList"));
		    playPosition--;
		   if(playPosition<0)
		   {
		   	 playPosition=0;
		   }
		   
		   PlayerPlugin.player("jump",musicList[playPosition]);
		   $("#playBut").attr("src","images/stop.png");
    }
	//下一首
	function next()
	{
		 var musicList=JSON.parse(storage.getItem("musicList"));
		   playPosition++;
		   if(musicList.length-1<playPosition)
		   {
		   	 playPosition=musicList.length;
		   }
		   
		   PlayerPlugin.player("jump",musicList[playPosition]);
		    $("#playBut").attr("src","images/stop.png");
	}
	//进度
	function progress()
	{
		PlayerPlugin.player("playInfo","");
	}
	//处理返回数据
	function dealWithData(data){
		var progress=JSON.parse(data);
		showProgress(progress.currentPosition,progress.duration);
        if(!progress.isPlaying)
		{
			window.clearInterval(timer);
		}
		console.log(data);	
	}
	//显示进度
	function showProgress(currentPosition,duration)
	{
		$("#progressInfo").html(millisecondsStrToDate(currentPosition)+"/"+millisecondsStrToDate(duration));
		
		var option={
			        showText:false,
		            max:duration,
					barImage: 'images/progressbg_green.gif'
	               };
           $("#progressBar").progressBar(currentPosition,option);
	}
	function millisecondsStrToDate(str){
        var   startyear   =   1970;  
        var   startmonth   =   1;  
        var   startday   =   1;  
        var   d,   s;  
        var   sep   =   ":";  
        d   =   new   Date();  
        d.setFullYear(startyear,   startmonth,   startday);  
        d.setTime(0);  
        d.setMilliseconds(Number(str));  
        s   =  d.getMinutes()   +   ":"   +   d.getSeconds();  
        return s;
      }
var PlayerPlugin={
	player: function(action,music){
                      return PhoneGap.exec(dealWithData, null, "PlayerPlugin", action, [music]);
     }
};

PhoneGap.addConstructor(function(){
    PhoneGap.addPlugin("playerPlugin", new PlayerPlugin());
});